home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gp_dosfs.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  3.3 KB  |  104 lines

  1. /* Copyright (C) 1992, 1993, 1996, 1998 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gp_dosfs.c,v 1.2 2000/09/19 19:00:24 lpd Exp $ */
  20. /* Common routines for MS-DOS (any compiler) and DesqView/X, */
  21. /* which has a MS-DOS-like file system. */
  22. #include "dos_.h"
  23. #include "gx.h"
  24. #include "gp.h"
  25.  
  26. /* ------ Printer accessing ------ */
  27.  
  28. /* Put a printer file (which might be stdout) into binary or text mode. */
  29. /* This is not a standard gp procedure, */
  30. /* but all MS-DOS configurations need it. */
  31. void
  32. gp_set_file_binary(int prnfno, bool binary)
  33. {
  34.     union REGS regs;
  35.  
  36.     regs.h.ah = 0x44;        /* ioctl */
  37.     regs.h.al = 0;        /* get device info */
  38.     regs.rshort.bx = prnfno;
  39.     intdos(®s, ®s);
  40.     if (regs.rshort.cflag != 0 || !(regs.h.dl & 0x80))
  41.     return;            /* error, or not a device */
  42.     if (binary)
  43.     regs.h.dl |= 0x20;    /* binary (no ^Z intervention) */
  44.     else
  45.     regs.h.dl &= ~0x20;    /* text */
  46.     regs.h.dh = 0;
  47.     regs.h.ah = 0x44;        /* ioctl */
  48.     regs.h.al = 1;        /* set device info */
  49.     intdos(®s, ®s);
  50. }
  51.  
  52. /* ------ File accessing ------ */
  53.  
  54. /* Set a file into binary or text mode. */
  55. int
  56. gp_setmode_binary(FILE * pfile, bool binary)
  57. {
  58.     gp_set_file_binary(fileno(pfile), binary);
  59.     return 0;            /* Fake out dos return status */
  60. }
  61.  
  62. /* ------ File names ------ */
  63.  
  64. /* Define the character used for separating file names in a list. */
  65. const char gp_file_name_list_separator = ';';
  66.  
  67. /* Define the string to be concatenated with the file mode */
  68. /* for opening files without end-of-line conversion. */
  69. const char gp_fmode_binary_suffix[] = "b";
  70.  
  71. /* Define the file modes for binary reading or writing. */
  72. const char gp_fmode_rb[] = "rb";
  73. const char gp_fmode_wb[] = "wb";
  74.  
  75. /* Answer whether a file name contains a directory/device specification, */
  76. /* i.e. is absolute (not directory- or device-relative). */
  77. bool
  78. gp_file_name_is_absolute(const char *fname, unsigned len)
  79. {                /* A file name is absolute if it contains a drive specification */
  80.     /* (second character is a :) or if it start with 0 or more .s */
  81.     /* followed by a / or \. */
  82.     if (len >= 2 && fname[1] == ':')
  83.     return true;
  84.     while (len && *fname == '.')
  85.     ++fname, --len;
  86.     return (len && (*fname == '/' || *fname == '\\'));
  87. }
  88.  
  89. /* Answer the string to be used for combining a directory/device prefix */
  90. /* with a base file name.  The file name is known to not be absolute. */
  91. const char *
  92. gp_file_name_concat_string(const char *prefix, unsigned plen,
  93.                const char *fname, unsigned len)
  94. {
  95.     if (plen > 0)
  96.     switch (prefix[plen - 1]) {
  97.         case ':':
  98.         case '/':
  99.         case '\\':
  100.         return "";
  101.     };
  102.     return "\\";
  103. }
  104.